<template>
  <ContentWrap>
    <!-- <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" /> -->

    <div class="mb-10px">
      <BaseButton type="primary" @click="AddAction">{{ t('action.add') }}</BaseButton>
    </div>
    <!-- 表格主体 -->
    <el-table
      :data="dataList"
      highlight-current-row
      stripe
      border
      v-loading="tableLoading"
      :cell-style="{ textAlign: 'center' }"
      :header-cell-style="{ textAlign: 'center' }"
    >
      <el-table-column
        :label="t('minescreenFirmwareVersion.firmwareVersion.fvid')"
        prop="fvid"
        min-width="100"
      />
      <el-table-column
        :label="t('minescreenFirmwareVersion.firmwareVersion.version_id')"
        min-width="100"
        prop="version_id"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        :label="t('minescreenFirmwareVersion.firmwareVersion.firmware_download_addr')"
        prop="firmware_download_addr"
        min-width="400"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        :label="t('minescreenFirmwareVersion.firmwareVersion.last_updated_date')"
        prop="last_updated_date"
        min-width="150"
        :show-overflow-tooltip="true"
      >
        <template #default="{}"> </template>
      </el-table-column>
      <el-table-column
        :label="t('minescreenFirmwareVersion.firmwareVersion.creator')"
        prop="creator"
        min-width="150"
        :show-overflow-tooltip="true"
      >
        <template #default="{}"> </template>
      </el-table-column>

      <el-table-column fixed="right" label="操作">
        <template #default="{ row }">
          <el-button @click="handleJump('edit', row)" size="small">
            {{ t('order.edit') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--    分页-->
    <Pagination
      :total="paginationTotal"
      v-model:page="form.pageIndex"
      v-model:limit="form.pageSize"
      @pagination="initialize"
    />
  </ContentWrap>
</template>

<script setup lang="ts">
const { push } = useRouter()
const { t } = useI18n()
import Pagination from '@/components/Pagination/index.vue'
import { ContentWrap } from '@/components/ContentWrap'
import { getListApi } from '@/api/minescreenFirmwareVersion/firmwareVersion/index'

const tableLoading = ref<boolean>(false)
const dataList = ref<any[]>([])
const paginationTotal = ref<number>(0)

const form = ref<Record<string, any>>({
  fvid: '',
  version_id: '',
  firmware_download_addr: '',
  last_updated_date: '',
  creator: '',
  pageIndex: 1,
  pageSize: 20
})

//初始化请求
const initialize = async () => {
  tableLoading.value = true
  const params = JSON.parse(JSON.stringify(form.value))
  delete params.date
  const resp = await getListApi(params)
  dataList.value = resp.data.list
  paginationTotal.value = resp.data.total
  tableLoading.value = false
}

onMounted(() => {
  // getDropDownBoxInfo()
  initialize()
})
const AddAction = () => {
  push('/minescreenFirmwareVersion/firmwareVersion/add')
}

//跳转
const handleJump = (type: string, row: Record<string, any>) => {
  push({
    path: `/minescreenFirmwareVersion/firmwareVersion/${type}`,
    query: { data: encodeURIComponent(JSON.stringify(row)) }
  })
}
</script>
